package com.tequila.core.service.impl;

import com.google.common.collect.Lists;
import com.tequila.core.dao.CardCouponDao;
import com.tequila.core.service.CardCouponService;
import com.tequila.domain.dto.CardCouponDto;
import com.tequila.domain.entity.CardCoupon;
import com.tequila.domain.query.CardCouponQuery;
import fe.core.Assert;
import fe.core.BeanHelper;
import fe.core.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CardCouponServiceImpl implements CardCouponService {
    public static final Logger logger = LoggerFactory.getLogger(CardCouponServiceImpl.class);

    @Resource
    private CardCouponDao cardCouponDao;

    @Override
    public Pagination<CardCouponDto> queryPageListByParam(CardCouponQuery query) {
        Assert.assertNotNull(query);
        int total = cardCouponDao.queryPageCountByParam(query);

        List<CardCouponDto> list = Lists.newArrayList();
        if (total > 0) {
            list = cardCouponDao.queryPageListByParam(query);
        }
        return new Pagination<>(query, list, total);
    }

    @Override
    public CardCouponDto queryById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        CardCoupon cardCoupon = cardCouponDao.queryById(id);
        CardCouponDto cardCouponDto = new CardCouponDto();
        BeanHelper.copyProperties(cardCouponDto,cardCoupon);
        return cardCouponDto;
    }

    @Override
    public List<CardCouponDto> queryByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return cardCouponDao.queryByIdList(idList);
    }

    @Override
    public List<CardCouponDto> queryListByParam(CardCouponQuery query) {
        Assert.assertNotNull(query,"query不能为空!");
        return cardCouponDao.queryListByParam(query);
    }


    @Override
    public Long insert(CardCoupon entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        cardCouponDao.insert(entity);
        return entity.getId();
    }

    @Override
    public Long save(CardCoupon entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        cardCouponDao.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public int updateById(CardCoupon param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return cardCouponDao.updateById(param);
    }

    @Override
    public int updateSelectiveById(CardCoupon param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return cardCouponDao.updateSelectiveById(param);
    }

    @Override
    public int deleteById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        return cardCouponDao.deleteById(id);
    }

    @Override
    public int deleteByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return cardCouponDao.deleteByIdList(idList);
    }
}
